<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
    <h1>axios响应拦截器</h1>
    <button id="btn">请求拦截</button>

    <script>
        const btn = document.getElementById('btn')

        // 设置axios实例
        const myAxios = axios.create({
            baseURL:'/',
            timeout:10000,
            headers:{}
        })

        // 设置响应拦截器
        myAxios.interceptors.response.use((response)=>{
            console.log(response);
            alert('响应信息拦截成功')
        },()=>{})

        btn.onclick = async function(){
            const re = await myAxios.get(
                '/getmsg',
                {
                    params:{
                        userId:'001'
                    }
                }
            )
            console.log(re);
        }

    </script>
</body>
</html>